package org.webautotest.reservation;


import org.openqa.selenium.By;

import cn.bmyi.webautotest.aimee.BrowserEmulator;
import cn.bmyi.webautotest.aimee.BrowserEmulator.Element;

/**
 * 封装选择套餐页面元素及操作
 * @author gaowen
 *
 */
public class ChoosePackagePage
{
	public BrowserEmulator browser;
	public String url;
	public static class PageElement
	{
		public static final String SEARCH_TITLE_XPATH="/html/body/div/header/div[1]";//标题
		public static final String SEARCH_LOGO_XPATH="/html/body/div/header/img";//瑞慈体检logo
		public static final String SEARCH_PACKAGE_XPATH="/html/body/div/div[1]/div[1]/dl/dt/a";//套餐
		public static final String SEARCH_LISTBUTTON_XPATH="/html/body/div/div[1]/div[1]/dl/dt";//下拉按钮
		public static final String SEARCH_TITLELIST_XPATH="/html/body/div/div[1]/div[1]/dl/dd";//下拉检查项
		public static final String SEARCH_NEXTBUTTON_XPATH="/html/body/div/div[1]/a";//下一步按钮
	}
	
	public ChoosePackagePage(BrowserEmulator browser)
	{
		this.browser=browser;
	}
	
	/**
	 * 获取标题栏标题
	 * @return 标题
	 */
	public String getTitle()
	{
		return browser.findElement("xpath", PageElement.SEARCH_TITLE_XPATH).getText();
	}
	
	/**
	 * 获取套餐名
	 * @return 套餐名
	 */
	public String getPackageName()
	{
		return browser.findElement("xpath", PageElement.SEARCH_PACKAGE_XPATH).getText();
	}
	
	/**
	 * 点击套餐项展开按钮
	 */
	public void clicListButton()
	{
		browser.findElement("xpath", PageElement.SEARCH_LISTBUTTON_XPATH).click();
	}
	
	/**
	 * 获取套餐项列表Attribute
	 * @return 套餐想列表Attribute
	 */
	public String getTitleListAttribute()
	{
		return browser.findElement("xpath", PageElement.SEARCH_TITLELIST_XPATH).getAttribute("style");
	}
	
	/**
	 * 点击选择套餐
	 */
	public void ChoosePackage()
	{
		browser.findElement("xpath", PageElement.SEARCH_PACKAGE_XPATH).click();
	}
	
	/**
	 * 点击下一步按钮
	 */
	public void clickNextButton()
	{
		By locator=By.xpath(PageElement.SEARCH_NEXTBUTTON_XPATH);
		Element married=browser.new Element(locator);
		married.waitUntilDisplay();
		browser.findElement("xpath", PageElement.SEARCH_NEXTBUTTON_XPATH).click();
	}
	
	/**
	 * 获取下一步按钮attribute
	 * @return 下一步按钮attribute
	 */
	public String getNextButtonAttribute()
	{
		return browser.findElement("xpath", PageElement.SEARCH_NEXTBUTTON_XPATH).getAttribute("class");
	}
	
	/**
	 * 判断Logo是否显示
	 * @return True:显示；False：未显示
	 */
	public boolean isLogeDisPlay()
	{
		try 
		{
			browser.findElement("xpath", PageElement.SEARCH_LOGO_XPATH);
			return true;
		}
		catch (Exception e) {
			return false;
		}
	}
	
	/**
	 * 完成选择体检套餐
	 */
	public void finishChoose()
	{
		this.ChoosePackage();
		this.clickNextButton();
	}
}
